package com.ruoyi.wapp.controller.base;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 * 
 */
public class Result extends HashMap<String, Object> implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private Result() {//默认成功
		put("code", "0000");
		put("msg", "成功");
	}

	public static Result exception(String code, String msg) {
		Result r = new Result();
		r.put("code", code);
		r.put("msg", "未知异常:"+msg);
		return r;
	}
	public static Result error(String code, String msg) {
		Result r = new Result();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}
	
	public static Result ok(Map<String, Object> map) {
		Result r = new Result();
		r.putAll(map);
		return r;
	}
	public static Result ok() {
		return new Result();
	}
	public static Result ok(String msg) {
		Result r = new Result();
		r.put("msg", msg);
		return new Result();
	}
	public Result put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
